﻿using System.Collections.Generic;
using System.Linq;
using Infrastructure.IoC;
using Ninject;

namespace Infrastructure.Events
{
    public class NinjectDomainEventHandlerFactory : IDomainEventHandlerFactory
    {
        public IEnumerable<IDomainEventHandler<T>> GetDomainEventHandlersFor<T>
                                              (T domainEvent) where T : IDomainEvent
        {
            var handlers = ObjectFactory
                             .Kernel
                             .GetAll(typeof(IDomainEventHandler<T>))
                             .ToList();

            return handlers.Select(obj => obj as IDomainEventHandler<T>).ToList();
        }
    }
}
